package com.iss.itemplate.controller;

import com.iss.itemplate.dto.AppDto;
import com.iss.itemplate.dto.ErrorCode;
import com.iss.itemplate.dto.JsonResponseDto;
import com.iss.itemplate.service.HelloService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * **********************************************************************
 * <p/>
 * iServiceSoft Inc © - 2009 All Rights Reserved
 * _____________________________________________
 * <p/>
 * NOTICE:  All information contained herein is, and remains
 * the property of iServiceSoft. Intellectual and technical concepts
 * contained herein are proprietary of iServiceSoft and may be covered
 * by U.S. and Foreign Patents, patents in process, and are protected
 * by trade secret or copyright law.
 * Dissemination of this information or reproduction of this material
 * is strictly forbidden unless prior written permission is obtained
 * from iServiceSoft Incorporated.
 * <p/>
 * ***********************************************************************
 */

@Controller
public class HelloController {
   @Autowired
   private HelloService helloService;

   @RequestMapping(value = "/hello/getName", method = RequestMethod.GET)
   public @ResponseBody String getAppName(HttpServletRequest request) {
      return helloService.getAppName();
   }

   @RequestMapping(value = "/hello/getAppInfo", method = RequestMethod.GET)
   public @ResponseBody
   JsonResponseDto<AppDto> getApp(HttpServletRequest request) {
      AppDto app = helloService.getApp();
      return new JsonResponseDto<AppDto>(app, ErrorCode.SUCCESS);
   }
   
   @SuppressWarnings("rawtypes")
   @RequestMapping(value = "/hello/insertAppInfo", method = RequestMethod.GET)
   public @ResponseBody
   JsonResponseDto insertAppInfo(HttpServletRequest request, @RequestBody AppDto appDto) {
      helloService.insertApp(appDto);
      return new JsonResponseDto(ErrorCode.SUCCESS);
   }
   
   @SuppressWarnings("rawtypes")
   @RequestMapping(value = "/hello/updateAppInfo", method = RequestMethod.GET)
   public @ResponseBody
   JsonResponseDto updateAppInfo(HttpServletRequest request, @RequestBody AppDto appDto) {
      helloService.updateApp(appDto);
      return new JsonResponseDto(ErrorCode.SUCCESS);
   }
   
   @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/hello/deleteAppInfo/{appId}", method = RequestMethod.GET)
    public @ResponseBody
    JsonResponseDto deleteAppInfo(HttpServletRequest request, @PathVariable Long appId) {
      helloService.deleteApp(appId);
      return new JsonResponseDto(ErrorCode.SUCCESS);
   }

   @RequestMapping(value = "/hello/sendEclaim", method = RequestMethod.GET)
   public @ResponseBody
   JsonResponseDto sendEclaim(HttpServletRequest request) {
      String contextPath = request.getSession().getServletContext().getRealPath("");
      helloService.sendEclaim(contextPath);
      return new JsonResponseDto(ErrorCode.SUCCESS);
   }

   @RequestMapping(value = "/hello/sendEligibility", method = RequestMethod.GET)
   public @ResponseBody
   JsonResponseDto sendEligibility(HttpServletRequest request) {
      String contextPath = request.getSession().getServletContext().getRealPath("");
      helloService.sendEligibility();
      return new JsonResponseDto(ErrorCode.SUCCESS);
   }
}
